package com.base.cn.platform.os.service.op.coupon;

import com.base.cn.platform.os.common.mybatis.BaseBiz;
import com.base.cn.platform.os.common.utils.DateUtils;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.dao.op.coupon.OpUserBirthdayCodeDao;
import com.base.cn.platform.os.entity.op.coupon.OpUserBirthdayCode;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 用户生日赠送优惠券Biz
 *
 * @author s.li
 * @create 2018-10-03-10:57
 */
@Service
public class OpUserBirthdayCodeBiz extends BaseBiz<OpUserBirthdayCode,OpUserBirthdayCodeDao> {

    /**
     * 查询用户的生日获取记录（当前年的）
     * @param userId 用户ID
     * @return 记录列表
     */
    public List<OpUserBirthdayCode> findUserBirthdayCodeList(BigDecimal userId){
        Date date = new Date();
        List<OpUserBirthdayCode> userBirthdayCodeList = this.find(" userId="+userId +" and DATE_FORMAT(createTime,'%Y') = DATE_FORMAT('"+date+"','%Y')",null,null);
        return userBirthdayCodeList;
    }

    /**
     * 判断用户是否获取当前年的生日优惠券
     * @param userId 用户ID
     * @return true获取过，false未获取过
     */
    public boolean isGetUserBirthdayCode(BigDecimal userId){
        List<OpUserBirthdayCode> userBirthdayCodeList = this.findUserBirthdayCodeList(userId);
        if(ObjectUtils.isNotEmpty(userBirthdayCodeList)){
            return true;
        }
        return false;
    }
}
